package com.wc.alorithm_blue_bridge._思维.Q1188;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;
import java.util.ArrayList;

/**
 * @Author congege
 * @Description 蓝桥骑士
 * https://www.lanqiao.cn/problems/1188/learning/?page=1&first_category_id=1&sort=students_count&second_category_id=8
 * @Date Created in 2023/10/30-20:45
 */
public class Main {
    public static void main(String[] args) {
        ArrayList<Integer> array = new ArrayList<>();
        array.add(0);
        Input sc = new Input();
        int n = sc.nextInt();
        int idx = 0;
        while (n-- > 0) {
            int rank = sc.nextInt();
            if (rank > array.get(idx)) {
                array.add(rank);
                idx++;
            } else {
                swap(rank, idx, array);
            }
        }
        System.out.println(idx);
    }

    static public void swap(int rank, int idx, ArrayList<Integer> array) {
        int left = 0;
        int right = idx;
        while (left <= right) {
            int mid = left + (right - left) / 2;
            int midNum = array.get(mid);
            if (rank > midNum) {
                left = mid + 1;
            } else {
                right = mid - 1;
            }
        }
        array.set(left, rank);
    }

    static class Input {
        StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));

        public int nextInt() {
            try {
                in.nextToken();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return (int) in.nval;
        }
    }
}
